package 斗地主;

import java.util.ArrayList;
import java.util.Collections;

public class PokerGame {
    //static

    //静态代码块
    //特点:随着类的加载而加载,而且只执行一次
    //创建一个牌和储存牌
    static ArrayList<String> list=new ArrayList<>();//此处加static的原因:便于静态代码块可以访问这个集合,同时也可以
    //使多个对象都可以访问这个集合实现共享.

    //准备牌
    static {

        //"♦", "♣", "♥", "♠"
        //"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"

        //创建数组储存花色和数字
        String[] color={"♦", "♣", "♥", "♠"};
        String[] number={"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};


        //添加牌到牌盒中-->♥3
        for (String s : color) {
            for (String s1 : number) {
                list.add(s+s1);
            }
        }
        //添加大王小王
        list.add("大王");
        list.add("小王");

    }
    public PokerGame(){
        //洗牌
        Collections.shuffle(list);

        //发牌
        ArrayList<String> lord=new ArrayList<>();
        ArrayList<String> player1=new ArrayList<>();
        ArrayList<String> player2=new ArrayList<>();
        ArrayList<String> player3=new ArrayList<>();

        //遍历集合给每一个玩家发牌
        for (int i = 0; i < list.size(); i++) {
            //获取每一张牌
            String poker=list.get(i);
            //如果想要更乱一张一张给每一个玩家只需要i%3的余数是几就给谁
            if (i<3){
                lord.add(list.get(i));
            } else if (i<20) {
                player1.add(list.get(i));
            } else if (i<37) {
                player2.add(list.get(i));
            }else {player3.add(list.get(i));}



        }
        //看牌
        lookPoker("玩家1",player1);
        lookPoker("玩家2",player2);
        lookPoker("玩家3",player3);
        lookPoker("底牌",lord);

    }
    public static void lookPoker(String playName ,ArrayList<String> player){
        System.out.print(playName+"：");
        for (String s : player) {
            System.out.print(s+" ");
        }
        System.out.println();
    }

}
